﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScriptEditor.Commands
{
    class Command_BgTransformPath : Command
    {
        public string bgName
        {
            get
            {
                return Value1;
            }
            set
            {
                Value1 = value;
            }
        }
        public float[] durations
        {
            get
            {
                string[] strs = Value2.Split(new char[] { ',' });
                float[] time = new float[strs.Length];
                for(int i = 0; i < strs.Length; i++)
                {
                    time[i] = float.Parse(strs[i]);
                }
                return time;
            }
            set
            {
                Value2 = value[0].ToString();
                for(int i = 1; i < value.Length; i++)
                {
                    Value2 += "," + value[i].ToString();
                }
            }
        }
        public Vector2[] positions
        {
            get
            {
                string[] strs = Value3.Split(new char[] { ',' });
                Vector2[] time = new Vector2[strs.Length];
                for (int i = 0; i < strs.Length; i++)
                {
                    time[i] = StringToVector2(strs[i]);
                }
                return time;
            }
            set
            {
                Value3 = Vector2ToString(value[0]);
                for (int i = 1; i < value.Length; i++)
                {
                    Value3 += "," + Vector2ToString(value[i]);
                }
            }
        }
        public Vector2[] scales
        {
            get
            {
                string[] strs = Value4.Split(new char[] { ',' });
                Vector2[] size = new Vector2[strs.Length];
                for (int i = 0; i < strs.Length; i++)
                {
                    size[i] = StringToVector2(strs[i]);
                }
                return size;
            }
            set
            {
                Value4 = Vector2ToString(value[0]);
                for (int i = 1; i < value.Length; i++)
                {
                    Value4 += "," + Vector2ToString(value[i]);
                }
            }
        }
        public Ease[] easeTypes
        {
            get
            {
                if (Value5 == "")
                {
                    return new Ease[0];
                }
                string[] strs = Value5.Split(new char[] { ',' });
                Ease[] type = new Ease[strs.Length];
                for (int i = 0; i < strs.Length; i++)
                {
                    type[i] = (Ease)Enum.Parse(typeof(Ease), strs[i]);
                }
                return type;
            }
            set
            {
                Value5 = value[0].ToString();
                for (int i = 1; i < value.Length; i++)
                {
                    Value5 += "," + value[i].ToString();
                }
            }
        }
        public Command_BgTransformPath()
        {
            CommandType = COMMANDTYPE.BgTransformPath;
            bgName = "请输入背景名";
            durations = new float[] { 0.5f };
            positions = new Vector2[] { new Vector2 { x = 0, y = 0 } };
            scales = new Vector2[] { new Vector2 { x = 1, y = 1 } };
            easeTypes = new Ease[] { Ease.Linear };
            Wait = true;
        }
        public Command_BgTransformPath(string BgName, float[] Durations, Vector2[] Positions, Vector2[] Scales, Ease[] EaseTypes)
        {
            CommandType = COMMANDTYPE.BgTransformPath;
            bgName = BgName;
            durations = Durations;
            positions = Positions;
            scales = Scales;
            easeTypes = EaseTypes;
            Wait = true;
        }
        public override string ToString()
        {
            string pos = "";
            foreach(Vector2 p in positions)
            {
                pos += Vector2ToString(p) + " ";
            }
            return CommandType.ToString() + ":\n" + "背景连续移动:" + bgName + "移动到" + pos;
        }
    }
}
